#include <bits/stdc++.h>

using namespace std;

void dfs(vector<list<int>> &graph, vector<bool> &visited, int x)
{
    if (visited[x] == true)
    {
        return;
    }

    visited[x] = true;
    list<int> next = graph[x];
    for (auto num : next)
    {
        dfs(graph, visited, num);
    }
}

int main()
{
    int n, m, s, t;
    cin >> n >> m;
    vector<list<int>> graph(n + 1);
    while (m--)
    {
        cin >> s >> t;
        graph[s].push_back(t);
    }
    vector<bool> visited(n + 1, false);
    dfs(graph, visited, 1);
    for (int i = 1; i <= n; i++)
    {
        if (visited[i] == false)
        {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}